css: Pass property_id to compute function
authorBenjamin Otte <otte@redhat.com>
Thu, 12 Jul 2012 01:43:15 +0000 (03:43 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 28 Aug 2012 13:40:56 +0000 (15:40 +0200)
This is a reorganization of how value computing should be done.
Previously the GtkCssStyleProperty.compute vfunc was supposed to take
care of special cases when it needed those for computation. However,
this proved to be very complicated in cases where values were nested and
only the last value (of a common type) needed to be special cased.

A common example for this was the fallback handling for unresolvable
colors.

Now, we pass the property's ID along with all compute functions so we
can do the special casing where it's necessary.
Note that no actual changes happen in this commit. This will happen in
follow-ups.

26 files changed:
gtk/gtkcssarrayvalue.c
gtk/gtkcssbgsizevalue.c
gtk/gtkcssbordervalue.c
gtk/gtkcsscornervalue.c
gtk/gtkcsseasevalue.c
gtk/gtkcssenginevalue.c
gtk/gtkcssenumvalue.c
gtk/gtkcssimage.c
gtk/gtkcssimagegradient.c
gtk/gtkcssimagelinear.c
gtk/gtkcssimageprivate.h
gtk/gtkcssimagevalue.c
gtk/gtkcssinheritvalue.c
gtk/gtkcssinitialvalue.c
gtk/gtkcssnumbervalue.c
gtk/gtkcsspositionvalue.c
gtk/gtkcssrepeatvalue.c
gtk/gtkcssrgbavalue.c
gtk/gtkcssshadowsvalue.c
gtk/gtkcssshadowvalue.c
gtk/gtkcssstringvalue.c
gtk/gtkcssstylepropertyimpl.c
gtk/gtkcsstypedvalue.c
gtk/gtkcssvalue.c
gtk/gtkcssvalueprivate.h
gtk/gtksymboliccolor.c

index 985d195762af11bbdb01d570cf417c14f94e4e41..a4fa0f4b62a961f704ee947f18850bf2534f2734 100644 (file)
@@ -42,6 +42,7 @@ gtk_css_value_array_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_array_compute (GtkCssValue     *value,
+                             guint            property_id,
                              GtkStyleContext *context)
 {
   GtkCssValue *result;
@@ -54,7 +55,7 @@ gtk_css_value_array_compute (GtkCssValue     *value,
   result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
   for (i = 0; i < value->n_values; i++)
     {
-      result->values[i] = _gtk_css_value_compute (value->values[i], context);
+      result->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
       changed |= (result->values[i] != value->values[i]);
     }
 
index 2ba0eb110ac7e0559e24c9d0de0e003ff0396265..38f605496e3d9b2b25b49b4bb1f8b3db7fe05650 100644 (file)
@@ -42,13 +42,14 @@ gtk_css_value_bg_size_free (GtkCssValue *value)
 
 GtkCssValue *
 gtk_css_value_bg_size_compute (GtkCssValue     *value,
+                               guint            property_id,
                                GtkStyleContext *context)
 {
   if (value->x == NULL && value->y == NULL)
     return _gtk_css_value_ref (value);
 
-  return _gtk_css_bg_size_value_new (value->x ? _gtk_css_value_compute (value->x, context) : NULL,
-                                     value->y ? _gtk_css_value_compute (value->y, context) : NULL);
+  return _gtk_css_bg_size_value_new (value->x ? _gtk_css_value_compute (value->x, property_id, context) : NULL,
+                                     value->y ? _gtk_css_value_compute (value->y, property_id, context) : NULL);
 }
 
 static gboolean
index 53ba12fcbebca99a3e7471316a683a5baf4710d5..45f7fd14e4a1aa7330af566b1b8de2723ce0aaf7 100644 (file)
@@ -43,6 +43,7 @@ gtk_css_value_border_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_border_compute (GtkCssValue     *value,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   GtkCssValue *computed;
@@ -56,7 +57,7 @@ gtk_css_value_border_compute (GtkCssValue     *value,
     {
       if (value->values[i])
         {
-          computed->values[i] = _gtk_css_value_compute (value->values[i], context);
+          computed->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
           changed |= (computed->values[i] != value->values[i]);
         }
     }
index 042c7a2059ce16bef515ef2f0103504139eeafca..7e41688950e71500e625a228c1af2aed41f62bac 100644 (file)
@@ -38,12 +38,13 @@ gtk_css_value_corner_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_corner_compute (GtkCssValue     *corner,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   GtkCssValue *x, *y;
 
-  x = _gtk_css_value_compute (corner->x, context);
-  y = _gtk_css_value_compute (corner->y, context);
+  x = _gtk_css_value_compute (corner->x, property_id, context);
+  y = _gtk_css_value_compute (corner->y, property_id, context);
   if (x == corner->x && y == corner->y)
     {
       _gtk_css_value_unref (x);
index 8728c822b1d4950e8592923c6a9a17fe6e3d7845..122d6c129965cf999285ee791bfe3be8b40b5017 100644 (file)
@@ -51,6 +51,7 @@ gtk_css_value_ease_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_ease_compute (GtkCssValue     *value,
+                            guint            property_id,
                             GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index 437a0b6921fb8105600b508a3af516a6ce232ee6..8041090a09c786b1629e44b98d599cf20356c36a 100644 (file)
@@ -36,6 +36,7 @@ gtk_css_value_engine_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_engine_compute (GtkCssValue     *value,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index d808ff7de8e91867635e71a4d4ed9e6ec1304227..fb9c836388e967ec8f4714e24c6b321f417fe107 100644 (file)
@@ -37,6 +37,7 @@ gtk_css_value_enum_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_enum_compute (GtkCssValue     *value,
+                            guint            property_id,
                             GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index f92d4e9d6ecc36c1dc64808a597cc586751a8d6a..e10de72d0368ff5299eb4676c27f3b5cf139f559 100644 (file)
@@ -58,6 +58,7 @@ gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
 
 static GtkCssImage *
 gtk_css_image_real_compute (GtkCssImage     *image,
+                            guint            property_id,
                             GtkStyleContext *context)
 {
   return g_object_ref (image);
@@ -115,6 +116,7 @@ _gtk_css_image_get_aspect_ratio (GtkCssImage *image)
 
 GtkCssImage *
 _gtk_css_image_compute (GtkCssImage     *image,
+                        guint            property_id,
                         GtkStyleContext *context)
 {
   GtkCssImageClass *klass;
@@ -124,7 +126,7 @@ _gtk_css_image_compute (GtkCssImage     *image,
 
   klass = GTK_CSS_IMAGE_GET_CLASS (image);
 
-  return klass->compute (image, context);
+  return klass->compute (image, property_id, context);
 }
 
 void
index 1398d65fc1e625b7435025125b01caf27903d40d..254ebc8c4ad666df18bf5fd13e088c6bb503d4f9 100644 (file)
@@ -28,6 +28,7 @@ G_DEFINE_TYPE (GtkCssImageGradient, _gtk_css_image_gradient, GTK_TYPE_CSS_IMAGE)
 
 static GtkCssImage *
 gtk_css_image_gradient_compute (GtkCssImage     *image,
+                                guint            property_id,
                                 GtkStyleContext *context)
 {
   GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
index ffb7775d16e46f2ce40dc11c702d24d092544ec1..e6440232a23b5f5bf27be1e9ae1434c599361acf 100644 (file)
@@ -410,6 +410,7 @@ gtk_css_image_linear_print (GtkCssImage *image,
 
 static GtkCssImage *
 gtk_css_image_linear_compute (GtkCssImage     *image,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   static const GdkRGBA transparent = { 0, 0, 0, 0 };
@@ -421,7 +422,7 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
   copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
   copy->repeating = linear->repeating;
 
-  copy->angle = _gtk_css_value_compute (linear->angle, context);
+  copy->angle = _gtk_css_value_compute (linear->angle, property_id, context);
   
   fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
   g_array_set_size (copy->stops, linear->stops->len);
@@ -438,7 +439,7 @@ gtk_css_image_linear_compute (GtkCssImage     *image,
                                                                 FALSE);
       
       if (stop->offset)
-        scopy->offset = _gtk_css_value_compute (stop->offset, context);
+        scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
       else
         scopy->offset = NULL;
     }
index 85014a9e4a7ef3a4b42afae2a2c6def6a60f2357..e14387ba3b78021dd0f48f47d357153de3eb91da 100644 (file)
@@ -56,6 +56,7 @@ struct _GtkCssImageClass
 
   /* create "computed value" in CSS terms, returns a new reference */
   GtkCssImage *(* compute)                         (GtkCssImage        *image,
+                                                    guint               property_id,
                                                     GtkStyleContext    *context);
 
   /* draw to 0,0 with the given width and height */
@@ -81,6 +82,7 @@ int            _gtk_css_image_get_height           (GtkCssImage        *image);
 double         _gtk_css_image_get_aspect_ratio     (GtkCssImage        *image);
 
 GtkCssImage *  _gtk_css_image_compute              (GtkCssImage        *image,
+                                                    guint               property_id,
                                                     GtkStyleContext    *context);
 
 void           _gtk_css_image_draw                 (GtkCssImage        *image,
index 6f65e2253e9bd814194d37a827443d22f4f75e8e..5cd4929234ba4036645b1671b7d1cb81b2517f68 100644 (file)
@@ -35,6 +35,7 @@ gtk_css_value_image_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_image_compute (GtkCssValue     *value,
+                             guint            property_id,
                              GtkStyleContext *context)
 {
   GtkCssImage *image, *computed;
@@ -44,7 +45,7 @@ gtk_css_value_image_compute (GtkCssValue     *value,
   if (image == NULL)
     return _gtk_css_value_ref (value);
 
-  computed = _gtk_css_image_compute (image, context);
+  computed = _gtk_css_image_compute (image, property_id, context);
 
   if (computed == image)
     {
index 52f21a0e41c0ecbfa8a5859db0a17febfaf4426c..614abe1125c1ba52011f6c9cdf0ff2c46ee0ea37 100644 (file)
@@ -32,6 +32,7 @@ gtk_css_value_inherit_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_inherit_compute (GtkCssValue     *value,
+                               guint            property_id,
                                GtkStyleContext *context)
 {
   /* This value should be caught further up */
index f838299de9d20f219d78f722f652f0aa69ad1522..24955c3b5899304ee63b371aa4641ed627804d69 100644 (file)
@@ -32,6 +32,7 @@ gtk_css_value_initial_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_initial_compute (GtkCssValue     *value,
+                               guint            property_id,
                                GtkStyleContext *context)
 {
   /* This value should be caught further up */
index c198e43764ca817ea0e5cc02660d8db96aa70306..c929f1d2740d273d4427e4f6ce6af705d1cbf53e 100644 (file)
@@ -35,6 +35,7 @@ gtk_css_value_number_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_number_compute (GtkCssValue     *number,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   switch (number->unit)
index e24420a05be7b1754bb7fc617d8de9895d13c25d..9f4b0d3f0ab6c062f039c36112c70b898cc5ccd5 100644 (file)
@@ -38,12 +38,13 @@ gtk_css_value_position_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_position_compute (GtkCssValue     *position,
+                                guint            property_id,
                                 GtkStyleContext *context)
 {
   GtkCssValue *x, *y;
 
-  x = _gtk_css_value_compute (position->x, context);
-  y = _gtk_css_value_compute (position->y, context);
+  x = _gtk_css_value_compute (position->x, property_id, context);
+  y = _gtk_css_value_compute (position->y, property_id, context);
   if (x == position->x && y == position->y)
     {
       _gtk_css_value_unref (x);
index 4151f9d48e0d2d1278ce339421b4388cca990664..97fe41f349a746c740c1e7f60516f709878251d1 100644 (file)
@@ -35,6 +35,7 @@ gtk_css_value_repeat_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_repeat_compute (GtkCssValue     *value,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index 88b8ea07675c1a8c5546fee464ba737792c0ae81..fc1642c392a0cf7a50c2508fe7cb9f0c752b4234 100644 (file)
@@ -36,6 +36,7 @@ gtk_css_value_rgba_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_rgba_compute (GtkCssValue     *value,
+                            guint            property_id,
                             GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index 2b105a5cd53b375046a5e403518f12d24942730c..387076eb38492cef7bbff4b5d1dd78770058c52f 100644 (file)
@@ -49,6 +49,7 @@ gtk_css_value_shadows_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_shadows_compute (GtkCssValue     *value,
+                               guint            property_id,
                                GtkStyleContext *context)
 {
   GtkCssValue *result;
@@ -60,7 +61,7 @@ gtk_css_value_shadows_compute (GtkCssValue     *value,
   result = gtk_css_shadows_value_new (value->values, value->len);
   for (i = 0; i < value->len; i++)
     {
-      result->values[i] = _gtk_css_value_compute (value->values[i], context);
+      result->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
     }
 
   return result;
index a1adfc9558705d1c7513bd2f0081add52f3974a5..dfd3b1c992b7eb1f523a7e52ed8f178793e8400d 100644 (file)
@@ -61,6 +61,7 @@ gtk_css_value_shadow_free (GtkCssValue *shadow)
 
 static GtkCssValue *
 gtk_css_value_shadow_compute (GtkCssValue     *shadow,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   GdkRGBA transparent = { 0, 0, 0, 0 };
@@ -73,10 +74,10 @@ gtk_css_value_shadow_compute (GtkCssValue     *shadow,
                                                      FALSE);
   _gtk_css_value_unref (fallback);
 
-  return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, context),
-                                   _gtk_css_value_compute (shadow->voffset, context),
-                                   _gtk_css_value_compute (shadow->radius, context),
-                                   _gtk_css_value_compute (shadow->spread, context),
+  return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, property_id, context),
+                                   _gtk_css_value_compute (shadow->voffset, property_id, context),
+                                   _gtk_css_value_compute (shadow->radius, property_id, context),
+                                   _gtk_css_value_compute (shadow->spread, property_id, context),
                                    shadow->inset,
                                    color);
 }
index b5813cd88420561c8b8ce194a17fe9bf8ee2c7e4..2bc140dd97bc20a5e82bce14cee4f43ab2927709 100644 (file)
@@ -34,6 +34,7 @@ gtk_css_value_string_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_string_compute (GtkCssValue     *value,
+                              guint            property_id,
                               GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index 48a69f06a01e7d9c0901624034996d9734e0f58f..162ab3a69ff8075d16e683cd7a2393a64adc20f9 100644 (file)
@@ -520,7 +520,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
                       GtkStyleContext     *context,
                       GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -535,7 +535,7 @@ border_corner_radius_value_compute (GtkCssStyleProperty *property,
                                     GtkStyleContext     *context,
                                     GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -561,7 +561,7 @@ css_image_value_compute (GtkCssStyleProperty    *property,
                          GtkStyleContext        *context,
                          GtkCssValue            *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static void
@@ -619,7 +619,7 @@ background_image_value_compute (GtkCssStyleProperty    *property,
                                 GtkStyleContext        *context,
                                 GtkCssValue            *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static void
@@ -657,7 +657,7 @@ font_size_compute (GtkCssStyleProperty *property,
                    GtkStyleContext     *context,
                    GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -674,7 +674,7 @@ outline_compute (GtkCssStyleProperty *property,
                  GtkStyleContext     *context,
                  GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -722,7 +722,7 @@ compute_border (GtkCssStyleProperty *property,
                 GtkStyleContext     *context,
                 GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -805,7 +805,7 @@ compute_margin (GtkCssStyleProperty *property,
                 GtkStyleContext     *context,
                 GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -823,7 +823,7 @@ compute_padding (GtkCssStyleProperty *property,
                  GtkStyleContext     *context,
                  GtkCssValue         *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -852,7 +852,7 @@ compute_border_width (GtkCssStyleProperty    *property,
       border_style == GTK_BORDER_STYLE_HIDDEN)
     return _gtk_css_number_value_new (0, GTK_CSS_PX);
   else
-    return _gtk_css_value_compute (specified, context);
+    return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -888,7 +888,7 @@ background_size_compute (GtkCssStyleProperty    *property,
                          GtkStyleContext        *context,
                          GtkCssValue            *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 static GtkCssValue *
@@ -903,7 +903,7 @@ background_position_compute (GtkCssStyleProperty    *property,
                             GtkStyleContext        *context,
                             GtkCssValue            *specified)
 {
-  return _gtk_css_value_compute (specified, context);
+  return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
 }
 
 /*** REGISTRATION ***/
index 81287a48e688866061051fd74730c144db06a032..eb98684d4071bf9730fcb123a6afdf505507ee76 100644 (file)
@@ -35,6 +35,7 @@ gtk_css_value_typed_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_typed_compute (GtkCssValue     *value,
+                             guint            property_id,
                              GtkStyleContext *context)
 {
   return _gtk_css_value_ref (value);
index 965d57359bb92d89c832c8ec88d4d30f9fcba073..d07a1ca113e0e2873542f39242e59698f5cd9cf7 100644 (file)
@@ -63,12 +63,13 @@ _gtk_css_value_unref (GtkCssValue *value)
 
 GtkCssValue *
 _gtk_css_value_compute (GtkCssValue     *value,
+                        guint            property_id,
                         GtkStyleContext *context)
 {
   g_return_val_if_fail (value != NULL, NULL);
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
 
-  return value->class->compute (value, context);
+  return value->class->compute (value, property_id, context);
 }
 
 gboolean
index 93fcaf979b79b75db40c4f668d1c943db7f31b71..74550f794e306ea92da038117bf0739e7b22eef1 100644 (file)
@@ -43,6 +43,7 @@ struct _GtkCssValueClass {
   void          (* free)                              (GtkCssValue                *value);
 
   GtkCssValue * (* compute)                           (GtkCssValue                *value,
+                                                       guint                       property_id,
                                                        GtkStyleContext            *context);
   gboolean      (* equal)                             (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
@@ -63,6 +64,7 @@ GtkCssValue *_gtk_css_value_ref                       (GtkCssValue
 void         _gtk_css_value_unref                     (GtkCssValue                *value);
 
 GtkCssValue *_gtk_css_value_compute                   (GtkCssValue                *value,
+                                                       guint                       property_id,
                                                        GtkStyleContext            *context);
 gboolean     _gtk_css_value_equal                     (const GtkCssValue          *value1,
                                                        const GtkCssValue          *value2);
index 6cfed7482121b39321b2f493f40dac17ef44cf9b..fe8656d0bc1abb74dde8409740551e5e6296aa84 100644 (file)
@@ -119,6 +119,7 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
 
 static GtkCssValue *
 gtk_css_value_symbolic_compute (GtkCssValue     *value,
+                                guint            property_id,
                                 GtkStyleContext *context)
 {
   /* for now we expect this to never be called